﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MarketOnlineDTO;
using MarketOnlineBUS;

public partial class cms_ManageProductType : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDanhSachLoaiSanPham();
            if (Session["key_Search"] != null)
            {
                txtTenLoai.Text = Session["key_search"].ToString();
                Session["key_search"] = null;
            }
        }
    }

    private void LoadDanhSachLoaiSanPham()
    {
        LoaiSanPhamBUS lspBUS = new LoaiSanPhamBUS();
        List<LoaiSanPhamDTO> list = new List<LoaiSanPhamDTO>();
        list = lspBUS.LayDanhSachLoaiSanPham();
        dtgvDanhSachLoaiSP.DataSource = list;
        dtgvDanhSachLoaiSP.DataBind();

        cmbMaLoaiSP.DataSource = list;
        cmbMaLoaiSP.DataTextField = "MaLoaiSP";
        cmbMaLoaiSP.DataValueField = "MaLoaiSP";
        cmbMaLoaiSP.DataBind();
    }
    
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        LoaiSanPhamBUS lspBUS = new LoaiSanPhamBUS();
        LoaiSanPhamDTO lspDTO = new LoaiSanPhamDTO();
        lspDTO.MaLoaiSP = Convert.ToInt32(cmbMaLoaiSP.SelectedValue);
        lspDTO.TenLoaiSP = txtTenLoai.Text;
        Boolean flag = lspBUS.CapNhatLoaiSanPham(lspDTO);
        LoadDanhSachLoaiSanPham();
    }
    protected void btnThemLoaiSanPham_Click(object sender, EventArgs e)
    {
        LoaiSanPhamBUS lspBUS = new LoaiSanPhamBUS();
        LoaiSanPhamDTO lspDTO = new LoaiSanPhamDTO();
        lspDTO.MaLoaiSP = 0;
        lspDTO.TenLoaiSP = txtTenLoai.Text;
        Boolean flag = lspBUS.ThemLoaiSanPham(lspDTO);
        LoadDanhSachLoaiSanPham();
    }
}